Fix MCP HTTP server resource leaks and error handling gaps#17
Merged
Conversation
Co-authored-by: mars167 <29228178+mars167@users.noreply.github.com>
- Add comprehensive error handling for HTTP requests and server connections - Fix session management to return session ID in response headers - Eliminate code duplication by consolidating handler setup into attachServerHandlers - Add graceful shutdown mechanism with SIGTERM/SIGINT handlers - Store both transport and server instances in session map - Add proper error handling for stateless mode - Fix race condition in session initialization Co-authored-by: mars167 <29228178+mars167@users.noreply.github.com>
- Create English MCP documentation (docs/mcp.md) - Update Chinese MCP documentation with HTTP improvements - Document session management and persistence - Document error handling and graceful shutdown - Update README.md and README.zh-CN.md with HTTP features - Add session usage examples Co-authored-by: mars167 <29228178+mars167@users.noreply.github.com>
Remove redundant 'as never' cast from Promise<never> return statement Co-authored-by: mars167 <29228178+mars167@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix issues in MCP HTTP connection implementation
Fix MCP HTTP server connection handling and session management
Feb 3, 2026
…nagement - Change signal handlers from on() to once() to prevent duplicates - Remove redundant setupServerHandlers() method (dead code) - Remove redundant String() type conversion - Add URL parsing error handling with 400 status - Add session race condition check with 410 status - Add proper transport cleanup on connection failures - Improve shutdown to properly close transports instead of just invoking callbacks - Add defensive check in onclose callback to prevent double-delete Co-authored-by: mars167 <29228178+mars167@users.noreply.github.com>
Copilot
AI
changed the title
Fix MCP HTTP server connection handling and session management
Fix MCP HTTP server resource leaks and error handling gaps
Feb 3, 2026
- Add stripLanguageKeywords() to symbolSearch.ts to remove language keywords (class, function, etc.) from search queries - Apply keyword stripping in filterAndRankSymbolRows before symbol matching - Add comprehensive diagnostics to handleRepoMap with detailed logging - Improve error messages for empty repo_map results with actionable suggestions - Enhance debugging capabilities for both handlers These changes improve MCP tool usability by: 1. Allowing natural language queries like 'class Project' instead of just 'Project' 2. Providing clear diagnostic information when searches return no results 3. Better error handling and user guidance for index-related issues
The package-lock.json was out of sync with package.json, causing CI to fail with 'Missing: hono@4.11.7 from lock file' error. Regenerated lock file by running: - rm -f package-lock.json - npm install Build and all tests verified passing locally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addressed code review feedback on MCP HTTP server implementation. Fixed resource leaks, race conditions, and missing error boundaries.
Resource Management
process.on()→process.once()to prevent duplicate registration on multiplestartHttp()callstransport.close()instead of invokingonclosecallback directly; wait for all transports to closetransport.close()in error paths for both stateless and session modesError Handling
Map.get(), returns 410 if session deleted betweenhas()andget()onclosecallback withsessions.has()checkCode Quality
setupServerHandlers()wrapper methodString()type conversion💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.